package com.example.qihuibao.widget.dialog

import android.view.View
import android.widget.*
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.example.qihuibao.R
import com.example.qihuibao.base.BaseDialogFragment
import com.example.qihuibao.bean.ReqAddDepartmentInfoBean
import com.example.qihuibao.bean.ReqUpdateDepartmentInfoBean
import com.example.qihuibao.module.main.MainActivity
import com.example.qihuibao.utils.extension.toast
import com.example.qihuibao.widget.view.CommonRecyclerView
import com.example.qihuibao.widget.view.EdittextWithText

/**
 *@author: cww
 *@desc:企业信息操作
 *@date: 5/16/23 10:58 AM
 */
class DepartmentInfoAddDialog() : BaseDialogFragment(R.layout.dialog_department_info_add) {

    override fun initView() {
        mView?.findViewById<View>(R.id.iv_close)?.setOnClickListener { dismiss() }
        mView?.findViewById<View>(R.id.btn_add)?.setOnClickListener { add() }
    }

    private fun add() {
        val id1 = mView?.findViewById<EditText>(R.id.et_dep_id1)?.text.toString()
        val name1 = mView?.findViewById<EditText>(R.id.et_dep_name1)?.text.toString()
        val id2 = mView?.findViewById<EditText>(R.id.et_dep_id2)?.text.toString()
        val name2 = mView?.findViewById<EditText>(R.id.et_dep_name2)?.text.toString()
        if (id1.isEmpty() || name1.isEmpty()) {
            activity?.toast("一级部门不能为空")
            return
        }
        (activity as MainActivity).getMainViewModel().addDepartmentInfo(ReqAddDepartmentInfoBean(id1, name1, id2, name2)).observe(this) {
            activity?.toast(if (it.RetCode == "0") "新增成功" else "新增失败")
            if (it.RetCode == "0") {
                dismiss()
            }
        }
    }

}